<?php

namespace app\mobileapp\controller;


class Notice extends Base
{
    /**
     * User: Simony
     * Function: 节目通知列表 (我关注的用户)
     */
    public function programNoticeList()
    {

        $memberId = $this->memberId;
        $page_size = input('post.per_page/d', 10);

        //我关注得用户
        $followBlacklistModel = model('common/member/FollowBlacklist');
        $where = ['member_id' => $memberId, 'type' => 1, 'status' => 1];
        $been_member_ids = $followBlacklistModel->getCol('been_member_id', $where);

        $contentModel = model('common/content/Content');
        $where = [
            'c.member_id' => $been_member_ids,
            'c.type' => 2,
        ];
        $field = "m.id as member_id,m.avatar,m.nickname,c.create_time,c.id as content_id";
        $res = $contentModel->getPageContentList($where, $page_size, $field, 'c.create_time desc');


        $data = $res;
        if (isset($data['data'])) {
            foreach ($data['data'] as &$v) {
                $v['desc'] = '发布了一条节目，点击查看';
                $v['date'] = date('Y-m-d H:i:s', $v['create_time']);
                unset($v['file']);
                unset($v['create_time']);
            }
        }
        $this->api_ajaxReturn(SUCCESS, '获取成功', $data);
    }

    /**
     * User: Simony
     * Function: 报名通知列表
     */
    public function signUpNoticeList()
    {
        $memberId = $this->memberId;
        $page_size = input('post.per_page/d', 10);
        $commentModel = model('common/content/Comment');

        $where = [
            'c.member_id' => $memberId,
            'c_c.type' => 2,
        ];
        $field = "m.id as member_id,m.avatar,m.nickname,c_c.create_time,c.location,c.begin_date,c.end_date,c.date_type,c.id content_id";
        $commentModel->getContentCommentList($where, $page_size, $field, 'c_c.create_time desc');

        $res = $commentModel->page_info;


        $data = $res ? $res->toArray() : [];
        $choose_list = config('app.choose_list');
        if (isset($data['data'])) {
            foreach ($data['data'] as &$v) {
                $v['date'] = date('Y-m-d H:i:s', $v['create_time']);
                $v['desc'] = '报名了您的节目，快去看看吧';

                if (isset($choose_list[$v['date_type']])) {
                    $v['program_desc'] = '(' . date('m月d日', $v['begin_date']) . $choose_list[$v['date_type']]['name'] . $v['location'] . ')';
                } else {
                    $v['program_desc'] = '(' . date('m月d日', $v['begin_date']) . '至' . date('m月d日', $v['end_date']) . $v['location'] . ')';
                }

                unset($v['create_time']);
                unset($v['begin_date']);
                unset($v['end_date']);
                unset($v['date_type']);
                unset($v['location']);
            }
        }


        $this->api_ajaxReturn(SUCCESS, '获取成功', $data);
    }


    /**
     * User: Simony
     * Function: 评论通知列表
     */
    public function commentNoticeList()
    {
        $memberId = $this->memberId;
        $page_size = input('post.per_page/d', 10);

        $commentModel = model('common/content/Comment');

        $where = [
            'c.member_id' => $memberId,
            'c_c.type' => 1,
        ];
        $field = "m.id as member_id,m.avatar,m.nickname,c_c.create_time,c.id content_id,c.type";
        $commentModel->getContentCommentList($where, $page_size, $field, 'c_c.create_time desc');

        $res = $commentModel->page_info;


        $data = $res ? $res->toArray() : [];

        if (isset($data['data'])) {
            foreach ($data['data'] as &$v) {
                $v['date'] = date('Y-m-d H:i:s', $v['create_time']);
                $v['desc'] = '评论了您得' . ($v['type'] == 1 ? '动态' : '节目') . '，快点看看吧';
                unset($v['create_time']);
                unset($v['type']);
            }
        }


        $this->api_ajaxReturn(SUCCESS, '获取成功', $data);
    }


    /**
     * User: Simony
     * Function: 收益消息列表
     */
    public function profitNoticeList()
    {
        $memberId = $this->memberId;
        $page_size = input('post.per_page/d', 10);

        $where = [
            'member_id' => $memberId,
            'op_type' => 4
        ];

        $blanceLogModel = model('common/member/BlanceLog');
        $field = 'desc,create_time';
        $blanceLogModel->getList($where, $page_size, $field, 'create_time desc');
        $res = $blanceLogModel->page_info;
        $data = $res ? $res->toArray() : [];
        if (isset($data['data'])) {
            foreach ($data['data'] as &$v) {
                $v['date'] = date('Y-m-d H:i:s', $v['create_time']);
                unset($v['create_time']);
            }
        }
        $this->api_ajaxReturn(SUCCESS, '获取成功', $data);
    }

    /**
     * User: Simony
     * Function: 系统消息列表
     */
    public function systemNoticeList()
    {
        $memberId = $this->memberId;
        $page_size = input('post.per_page/d', 10);


        $member = model('common/member/Member')->getInfoByID($memberId);

        $where = [
            ['member_id', 'eq', -1],//系统用户
            ['receive_member_id', 'in', -1 . ',' . $memberId],//系统用户
            ['type', 'eq', 0], //系统消息
            ['create_time', 'egt', $member['create_time']],//系统用户
        ];

        $messageModel = model('common/message/Message');
        $field = 'content,create_time';
        $messageModel->getList($where, $page_size, $field, 'create_time desc');
        $res = $messageModel->page_info;
        $data = $res ? $res->toArray() : [];
        if (isset($data['data'])) {
            foreach ($data['data'] as &$v) {
                $v['date'] = date('Y-m-d H:i:s', $v['create_time']);
                unset($v['create_time']);
            }
        }

        $this->api_ajaxReturn(SUCCESS, '获取成功', $data);
    }

    /**
     * User: Simony
     * Function:评价消息列表
     */
    public function evaluateNoticeList()
    {
        $memberId = $this->memberId;

        $page_size = input('post.per_page/d', 10);

        $where = [
            'mess.member_id' => -1, //系统用户
            'mess.receive_member_id' => $memberId,
            'mess.type' => 1 //评价消息
        ];
        $messageModel = model('common/message/Message');

        $field = 'm.id as member_id,m.avatar,m.nickname,m.sex,mess.create_time';
        $res = $messageModel->alias('mess')
            ->join('member m', 'mess.relation_member_id=m.id')
            ->field($field)
            ->where($where)
            ->order('mess.create_time desc')
            ->paginate($page_size, false, ['query' => request()->param()]);
        $data = $res ? $res->toArray() : [];

        if (isset($data['data'])) {
            foreach ($data['data'] as &$v) {
                $v['date'] = date('Y-m-d H:i:s', $v['create_time']);
                $v['desc'] = '与【' . $v['nickname'] . '】' . '的交流愉快吗？评价一下' . ($v['sex'] == 1 ? '他' : '她') . '吧';
                unset($v['create_time']);
                unset($v['nickname']);
                unset($v['sex']);
            }
        }

        $this->api_ajaxReturn(SUCCESS, '获取成功', $data);
    }
}